//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateWork {
        private readonly IWorkRepository _workRepository;

        public CreateWork(IWorkRepository workRepository) {
            _workRepository = workRepository;
        }

        public void Execute(Guid userId, ICreateWorkCommand workForm) {
            if (workForm == null)
                throw new ArgumentNullException("workForm");

            try {
                var work = workForm.ConvertToEntity();
                _workRepository.Create(work);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
